<?php
// create custom plugin settings menu
add_action('admin_menu', 'errlog_create_menu');

function errlog_create_menu() {

	//create new dashboard menu page
	add_dashboard_page('Error Log', 'Error Log', 'administrator', __FILE__, 'errlog_settings_page', 'favicon.ico', '3');
        
	//call register settings function
	add_action( 'admin_init', 'register_errlogsettings' );
}

function register_errlogsettings() {
	//register our settings
	register_setting( 'errlog-settings-group', 'errlog_tracking_code' );
}

function errlog_settings_page() {
?>
<div class="wrap">

<h2>Silicon Solar Website Error Log</h2>

<?php

   $args = array('page_id' => 28527);
   $errorlog = new WP_Query($args);

   if($errorlog->have_posts()) : 
      while($errorlog->have_posts()) : 
         $errorlog->the_post();
?>

    <?php if (get_field('errorlogentry')) { ?>
        <table width="85%" cell-spacing="0px" cell-padding="0px" border="0px">
            <tr>
                <td style="height:40px;line-height:40px;background:#f2f2f2;font-size:15px;font-weight:bold;">Date</td>
                <td style="height:40px;line-height:40px;background:#f2f2f2;font-size:15px;font-weight:bold;">Error</td>
                <td style="height:40px;line-height:40px;background:#f2f2f2;font-size:15px;font-weight:bold;">Notes</td>
                <td style="height:40px;line-height:40px;background:#f2f2f2;font-size:15px;font-weight:bold;text-align:right;padding-right:20px;">Status</td>
            </tr>
        <?php while(has_sub_field('errorlogentry')) : ?>
            <tr>
                <td style="padding-top:10px;padding-bottom:10px;border-bottom:#cccccc 1px solid;padding-left:10px;padding-right:20px;"><?php the_sub_field('errorlog_date'); ?></td>
                <td style="padding-top:10px;padding-bottom:10px;border-bottom:#cccccc 1px solid;padding-right:20px;"><?php the_sub_field('errorlog_error'); ?></td>
                <td style="padding-top:10px;padding-bottom:10px;border-bottom:#cccccc 1px solid;padding-right:20px;"><?php the_sub_field('errorlog_notes'); ?></td>
                <td style="padding-top:10px;padding-bottom:10px;border-bottom:#cccccc 1px solid;padding-left:10px;padding-right:20px;text-align:right"><?php the_sub_field('errorlog_status'); ?></td>
            </tr>
        <?php endwhile; ?>
        </table>
    <?php } ?>

<?php
      endwhile;
   else: 
?>

      <p>Oops, there are no errors listed</p>

<?php
   endif;
?>

</div>
<?php } ?>